package com.arpa.oms.controller;

import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.arpa.core.web.MediaTypes;
import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.Page;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.wms.domain.dto.InventoryStatusDTO;
import com.arpa.wms.domain.entity.InventoryStatus;
import com.arpa.wms.domain.enums.StatusEnum;
import com.arpa.wms.domain.vo.InventoryStatusVO;
import com.arpa.wms.domain.vo.WarehouseVO;
import com.arpa.wms.service.IInventoryService;
import com.arpa.wms.service.IInventoryStatusService;
import com.arpa.wms.service.IReceiveRegisterService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * Oms库存状态 Controller
 * </p>
 *
 * @author wangdong
 * @since 2021-07-21
 */
@Api(tags = "库存状态")
@RestController
@RequestMapping(value="/omsInventoryStatus", produces = "application/json;charset=UTF-8")
@Log4j2
public class OmsInventoryStatusController {

   @Autowired
   private IInventoryStatusService  iInventoryStatusService;

   @Autowired
   private IReceiveRegisterService iReceiveRegisterService;

   @Autowired
   private IInventoryService iInventoryService;

    /**
     * 获取 库存状态 列表
     *
     * @param inventoryStatusDTO
     * @param request
     * @return
     */
    @ApiOperation(value = "获取 库存状态 列表", notes = "获取 库存状态 列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
        @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success", response = InventoryStatusVO.class))
    @NeedLogin
    @GetMapping()
    public Result list(InventoryStatusDTO inventoryStatusDTO,HttpServletRequest request) {
        try {
            inventoryStatusDTO.setShipmentCode(UserUtil.getLoginWarehouseCodeOrShipmentCode());
            InventoryStatusVO inventoryStatusVOSum = iInventoryStatusService.queryListSum(inventoryStatusDTO);
            List<InventoryStatusVO> inventoryStatusVOList = iInventoryStatusService.queryList(inventoryStatusDTO);

            inventoryStatusVOList.forEach(info ->{
                info.getStatus();
                StatusEnum enumByValue = StatusEnum.getEnumByValue(info.getStatus());
                if(null != enumByValue){
                    //启用or停用
                    info.setStatusText(enumByValue.getDesc());
                }
            });
            Page returnPage = new Page(inventoryStatusDTO.getPageNum(),inventoryStatusDTO.getPageSize());
            returnPage.setRecords(inventoryStatusVOList);
            returnPage.setTotal(inventoryStatusVOSum.getTotal());
            returnPage.setSumObject(inventoryStatusVOSum);
            return Result.ok().data(returnPage);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE,e);
            return Result.error(e.getMessage());
        }
    }


}
